package Mode;

import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.ReentrantLock;

/**
 * ReentrantLock 和  Semaphore
 */

public class Test9 {
    public static void main(String[] args) throws InterruptedException {
        // 初始化的值表示可用资源有 4 个.
        Semaphore semaphore = new Semaphore(2);
        // 申请资源, P 操作
        semaphore.acquire();
        System.out.println("1");
        semaphore.acquire();
        System.out.println("2");
        semaphore.acquire();
        System.out.println("3");
        semaphore.acquire();
        // 释放资源, V 操作
        // semaphore.release();
    }

    public static void main1(String[] args) {
        ReentrantLock locker = new ReentrantLock();
        // 加锁
        locker.lock();
        // 抛出异常了. 就容易导致 unlock 执行不到~~
        // 解锁
        locker.unlock();
    }
}
